#!/usr/bin/env bash
ClangbuilderDir=$(cd `dirname $0`; pwd)

if [[ ! -f "$ClangbuilderDir/branch" ]]; then
  Branch="release_50"
else
  source "$ClangbuilderDir/branch"
fi


OutDir="$ClangbuilderDir/stable"

if [[ -d $OutDir ]]; then
  #statements
  cd $OutDir
  # mybe need cleanup
else
  mkdir $OutDir
  cd $OutDir
fi

CC=clang
CXX=clang++

hash clang 2>/dev/null || {
  echo "We need use gcc to build llvm and clang."
  CC=gcc
  CXX=g++
}



cmake -DCMAKE_BUILD_TYPE=Release  -DLLVM_ENABLE_ASSERTIONS=OFF -DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" -DLLVM_HOST_TRIPLE="x86_64-fbi-linux-gnu" -DCLANG_REPOSITORY_STRING="fbi.io" "../$Branch"
#cmake -DCMAKE_BUILD_TYPE=Release  -DLLVM_ENABLE_ASSERTIONS=OFF
echo "Please run make -j N to build llvm:"
